package com.shaozi.nc.hibservice;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shaozi.nc.data.hibVO.CrmOrderVO;
import com.shaozi.data.hib.dao.BaseHibDao;
import com.shaozi.data.hib.service.BaseServiceImpl;
import com.shaozi.lib.throwable.SzException;
import com.shaozi.utils.common.SysUtils;

@Service(value = "crmOrderService")
public class CrmOrderService extends BaseServiceImpl<CrmOrderVO> {

	@Autowired
	public CrmOrderService(BaseHibDao<CrmOrderVO> baseHibDao) {
		super(baseHibDao);
	}

	/**
	 * select customer_id from desk_crm_order where approve_status=2 and
	 * is_delete=0 and customer_id in($customerId) 已审批过的人员
	 * 
	 * @return
	 * @throws SzException
	 */
	public List<Integer> approvedCustomers(List<Integer> customerIds) throws SzException {
		String hql = "from CrmOrderVO where approveStatus=2 and isDelete=0 and customerId in("
				+ SysUtils.combineList(customerIds, ",") + ")";
		List<CrmOrderVO> orders = getDao().getDaoSupport().queryObjects(hql, -1, -1);
		final List<Integer> ret = new ArrayList<>(orders.size());
		orders.forEach(order -> ret.add(order.getCustomerId()));
		return ret;
	}

}
